#include <stdio.h>
#include <stdlib.h>
#include <csp_spu.h>
#include <csp_debug.h>

int global_pid; 

unsigned char _75KB[75][1024];

void heavy_computation(unsigned char recursions){
	int x,y;
	int t = 2;
	if( 0 == recursions ){
		return;
	}
	while(t--){
	for(x=0; x < 75; x++){
		for(y=0; y < 1024; y++){
			_75KB[x][y] += 1;	
		}
	}
	}
	csp_yield();
	heavy_computation(recursions-1);
}


void test(unsigned char test_value){
	int x, y;
	for(x=0; x < 75; x++){
		for(y=0; y < 1024; y++){
			ASSERT( test_value ==  _75KB[x][y] );	
		}
	}	
	printf("_75KB[33][1001]=%u\n", (uint32_t) _75KB[33][1001] );
}

int Run(){
	unsigned char test_value;
	int pid = csp_pid();

	global_pid = csp_pid();

	test_value = (unsigned char) (pid % 100)+10;

	heavy_computation(test_value);

	test(test_value);

	ASSERT( pid == csp_pid() );
	ASSERT( global_pid == csp_pid() );

	PRINTF_FOR_TESTING("%s terminating on spe #%i with pid %i\n",__FILE__ , csp_spe_id(), pid);

	PRINTF_FOR_TESTING("Nested task with pid=%i terminated with res=%i.\n", pid, res);

	return 0;
}
